package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportProjLoan;
import com.xjy.system.domain.bo.ReportProjLoanQueryBo;
import com.xjy.system.domain.vo.ReportProjLoanVo;
import com.xjy.system.mapper.ReportProjLoanMapper;
import com.xjy.system.service.IReportProjLoanService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 借款情况Service业务层处理
 *
 * @author mlb
 * @date 2022-03-15
 */
@Service
public class ReportProjLoanServiceImpl extends ServicePlusImpl<ReportProjLoanMapper, ReportProjLoan> implements IReportProjLoanService {

    @Override
    public ReportProjLoanVo queryById(Long projId){
        return getVoById(projId, ReportProjLoanVo.class);
    }

    @Override
    public TableDataInfo<ReportProjLoanVo> queryPageList(ReportProjLoanQueryBo bo) {
        PagePlus<ReportProjLoan, ReportProjLoanVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportProjLoanVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportProjLoanVo> queryList(ReportProjLoanQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportProjLoanVo.class);
    }

    private LambdaQueryWrapper<ReportProjLoan> buildQueryWrapper(ReportProjLoanQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportProjLoan> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(bo.getProjName()), ReportProjLoan::getProjName, bo.getProjName());
        lqw.like(StrUtil.isNotBlank(bo.getBorrower()), ReportProjLoan::getBorrower, bo.getBorrower());
        return lqw;
    }
}
